package com.sunmouse.toolkit.fragment.chart;


import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.sunmouse.toolkit.R;
import com.sunmouse.toolkit.fragment.BaseFragment;

import java.util.ArrayList;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.Unbinder;
import lecho.lib.hellocharts.model.BubbleChartData;
import lecho.lib.hellocharts.model.BubbleValue;
import lecho.lib.hellocharts.view.BubbleChartView;

/**
 * A simple {@link Fragment} subclass.
 */
public class BubbleFragment extends BaseFragment {


    @BindView(R.id.bubble_chart)
    BubbleChartView bubbleChart;
    Unbinder unbinder;

    public BubbleFragment() {
        // Required empty public constructor
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View view = inflater.inflate(R.layout.fragment_bubble, container, false);
        unbinder = ButterKnife.bind(this, view);
        return view;
    }

    @Override
    public void init() {
        ArrayList<BubbleValue> values = generateValues();
        BubbleChartData bubbleData = generateData(values);
        this.bubbleChart.setBubbleChartData(bubbleData);
    }

    private BubbleChartData generateData(ArrayList<BubbleValue> values) {
        BubbleChartData data = new BubbleChartData(values);
        data.setAxisXBottom(generateXAxis());
        data.setAxisYLeft(generateYAxis());
        data.setHasLabels(true);
        return data;
    }

    private ArrayList<BubbleValue> generateValues() {
        ArrayList<BubbleValue> values = new ArrayList<>();
        for (int i = 0; i < 7; i++) {
            BubbleValue value = new BubbleValue((i + 1), i + 1, i + 2, getCircleColor());
            value.setLabel("label-" + (i + 1));
            values.add(value);

        }
        return values;
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        unbinder.unbind();
    }
}
